import 'package:flutter/material.dart';
import 'package:flutter_demo/model/post.dart';

class CardDemo extends StatefulWidget {
  const CardDemo({super.key});

  @override
  State<CardDemo> createState() => _CardDemoState();
}

class _CardDemoState extends State<CardDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('CardDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: ListView(
            children: posts.map((posts) {
          return Card(
            child: Column(
              children: [
                AspectRatio(
                    aspectRatio: 16 / 9,
                    child: ClipRRect( //圆角
                      borderRadius: const BorderRadius.only(
                        topLeft: Radius.circular(4.0),
                        topRight: Radius.circular(4.0),
                      ),
                      child: Image.network(
                        posts.imageUrl!,
                        fit: BoxFit.cover,
                      ),
                    )),
                ListTile(
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage(posts.imageUrl!),
                  ),
                  title: Text(posts.title!),
                  subtitle: Text(posts.author!),
                ),
                Container(
                  padding: EdgeInsets.all(16.0),
                  child: Text(
                    posts.description!,
                    maxLines: 2,
                    overflow: TextOverflow.clip,
                  ),
                ),
                ButtonTheme(
                    child: ButtonBar(
                  children: [
                    FlatButton(
                        onPressed: () {}, child: Text('Like'.toUpperCase())),
                    FlatButton(
                        onPressed: () {}, child: Text('Read'.toUpperCase()))
                  ],
                ))
              ],
            ),
          );
        }).toList()),
      ),
    );
  }
}
